import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common';
import { OrderService } from './order.service';
import { CreateOrderDto } from './dto/create-order.dto';
import { UpdateOrderDto } from './dto/update-order.dto';
import { ApiBearerAuth, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
import { Public } from '../auth/decorators/public.decorator';

@ApiBearerAuth()
@ApiTags('订单')
@Controller('order')
export class OrderController {
  constructor(private readonly orderService: OrderService) {}

  @Post('submitOrder')
  @ApiOperation({ summary: '下单', description: '下单' })
  async submitOrder(@Body() params: any) {
    return await this.orderService.submitOrder(params);
  }

  @Get('orderList')
  @ApiOperation({ summary: '订单(委托)列表', description: '订单(委托)列表' })
  @ApiQuery({ name: 'status', description: 'open当前委托, finished历史委托', required: false })
  @ApiQuery({ name: 'contract', description: '合约 contract', required: false })
  async orderList(@Query() params: any) {
    return this.orderService.orderList(params);
    // 订单列表-my-勿删
    // return this.orderService.myOrderList(params);
  }

  @Get('historyOrder')
  @ApiOperation({ summary: '历史订单', description: '历史订单' })
  async historyOrder(@Query() params: any) {
    return this.orderService.historyOrder(params);
  }

  @Get('myHistoryOrder')
  @ApiOperation({ summary: '历史订单新' })
  async myHistoryOrder(@Query() params: any) {
    return this.orderService.myHistoryOrder(params);
  }

  // 注意在gate网站中取 id_string，不是id
  @Get('delOrder')
  @ApiOperation({ summary: '撤单', description: '撤单' })
  @ApiQuery({ name: 'id', description: '订单id', required: true })
  async delOrder(@Query() params: any) {
    return await this.orderService.delOrder(params?.id);
  }

  // 后台====
  @Get('htOrderList')
  @ApiOperation({ summary: '后台订单列表', description: '后台订单列表' })
  @ApiQuery({ name: 'status', description: 'open当前委托, finished历史委托', required: false })
  @ApiQuery({ name: 'contract', description: '合约 contract', required: false })
  async htOrderList(@Query() params: any) {
    return this.orderService.htOrderList(params);
  }

  @Get('tongBuWeituo')
  @ApiOperation({ summary: '定时同步芝麻的历史委托' })
  tongBuHistoryPositions(@Query() params: any) {
    return this.orderService.tongBuWeituo(params);
  }

  @Public()
  @Get('delWeiTuos')
  @ApiOperation({ summary: '删除所有历史委托' })
  async delWeiTuos(@Query() params: any) {
    return this.orderService.delWeiTuos();
  }

  @Get('myTrades')
  @ApiOperation({ summary: '成交记录', description: '成交记录' })
  async myTrades(@Query() params: any) {
    return await this.orderService.myTrades(params);
  }

  @Get('myTradesNew')
  @ApiOperation({ summary: '成交记录新', description: '成交记录' })
  async myTradesNew(@Query() params: any) {
    return await this.orderService.myTradesNew(params);
  }

  @Get('tongBuChengJiao')
  @ApiOperation({ summary: '定时同步芝麻的成交记录' })
  tongBuChengJiao(@Query() params: any) {
    return this.orderService.tongBuChengJiao(params);
  }

  @Get('delChengJiaos')
  @ApiOperation({ summary: '删除所有成交记录' })
  async delChengJiaos(@Query() params: any) {
    return await this.orderService.delChengJiaos();
  }
}
